package cn.iocoder.yudao.module.worker.dal.mysql.trendlike;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.worker.controller.app.trendlike.vo.AppTrendLikePageReqVO;
import cn.iocoder.yudao.module.worker.dal.dataobject.trendlike.TrendLikeDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.worker.controller.admin.trendlike.vo.*;

/**
 * 动态点赞 Mapper
 *
 * @author Jerry
 */
@Mapper
public interface TrendLikeMapper extends BaseMapperX<TrendLikeDO> {

    default PageResult<TrendLikeDO> selectPage(TrendLikePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TrendLikeDO>()
                .eqIfPresent(TrendLikeDO::getTrendId, reqVO.getTrendId())
                .eqIfPresent(TrendLikeDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(TrendLikeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TrendLikeDO::getId));
    }

    default PageResult<TrendLikeDO> selectPage(AppTrendLikePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TrendLikeDO>()
                .eqIfPresent(TrendLikeDO::getTrendId, reqVO.getTrendId())
                .eqIfPresent(TrendLikeDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(TrendLikeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TrendLikeDO::getId));
    }

    default TrendLikeDO getTrendLike(Long userId, Long trendId){
        return selectOne(new LambdaQueryWrapperX<TrendLikeDO>()
                .eqIfPresent(TrendLikeDO::getTrendId, trendId)
                .eqIfPresent(TrendLikeDO::getUserId, userId));
    }

    default Integer getTrendLikeCount(Long trendId){
        return selectJoinOne(Integer.class, new MPJLambdaWrapperX<TrendLikeDO>()
                .selectCount(TrendLikeDO::getId)
                .eq(TrendLikeDO::getTrendId, trendId));
    }

    default List<TrendLikeDO> getTrendLikeList(Long userId, Set<Long> trendIds){
        return selectList(new LambdaQueryWrapperX<TrendLikeDO>()
                .inIfPresent(TrendLikeDO::getTrendId, trendIds)
                .eqIfPresent(TrendLikeDO::getUserId, userId));
    }
}